<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 500px;
            height: 400px;
            margin: 100px auto;
            border: 1px solid black;
            text-align: center;
        }

        .content {
            width: 80%;
            height: 80%;
            margin: 20px auto;
            border: 1px solid black;
        }

        .cart {
            position: absolute;
            background-color: aqua;
            top: 100px;
            right: 50px;
            width: 30px;
            height: 20px;
        }

        .ac {
            position: absolute;
            background-color: red;
            width: 20px;
            height: 20px;
        }
    </style>
</head>

<body>

    <div class="box">
        <div class="content">

        </div>
        <button>
            添加
        </button>
    </div>
    <div class="cart">

    </div>

</body>
<script>
    class Shoping {
        constructor() {
            this.box = document.querySelector(".box")
            this.btn = this.box.querySelector("button")
            this.cart = document.querySelector(".cart")
            this.init()
        }
        init() {
            var x2 = this.cart.offsetLeft
            var y2 = this.cart.offsetTop
            var x3 = x2 - 100
            var y3 = 10
            this.btn.onclick = e => {
                var x1 = e.clientX
                var y1 = e.clientY
                this.a = -((y2 - y3) * x1 - (x2 - x3) * y1 + x2 * y3 - x3 * y2) / ((x2 - x3) * (x1 - x2) * (x1 - x3));
                this.b = ((y2 - y3) * x1 * x1 + x2 * x2 * y3 - x3 * x3 * y2 - (x2 * x2 - x3 * x3) * y1) / ((x2 - x3) * (x1 - x2) * (x1 - x3));
                this.c = ((x2 * y3 - x3 * y2) * x1 * x1 - (x2 * x2 * y3 - x3 * x3 * y2) * x1 + (x2 * x2 * x3 - x2 * x3 * x3) * y1) / ((x2 - x3) * (x1 - x2) * (x1 - x3));
                this.fly(x1, x2, y1, y2)
            }
        }
        fly(x1, x2, y1, y2) {
            var p = document.createElement("p")
            this.box.appendChild(p)
            p.style.left = x1 + "px"
            p.style.top = this.a * x1 * x1 + this.b * x1 + this.c - 20 + "px"
            p.className = "ac"
            var timer = setInterval(() => {
                p.style.left = x1 + "px"
                p.style.top = this.a * x1 * x1 + this.b * x1 + this.c - 20 + "px"
                x1 += 10
                if (x1 >= x2) {
                    clearInterval(timer)
                    this.box.removeChild(p)
                }
            }, 20)
        }
    }
    new Shoping()
</script>

</html>